﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;

namespace OPLService.BusinessEntities
{
    /// <summary>
    /// Wrapper class to carry data and errors if any
    /// </summary>
    [DataContract]
    [KnownType(typeof(List<Notification>))]
    [KnownType(typeof(Notification))]
    public class DTO
    {
        #region Private Members
        private String _errorMessage;
        private object _result;
        private ErrorCode _error;
        #endregion

        #region Constructors
        /// <summary>
        /// Construtor
        /// </summary>
        /// <param name="error">Error Message to be passed to client side</param>
        /// <param name="code">Error code to indicate the error</param>
        public DTO(String errorMessage, ErrorCode error)
            : this(null, errorMessage, error)
        {

        }

        /// <summary>
        /// Construtor
        /// </summary>
        /// <param name="result">Result of the Service Execution</param>
        public DTO(object result)
            : this(result, string.Empty, ErrorCode.Success)
        {

        }

        /// <summary>
        /// Construtor
        /// </summary>
        /// <param name="result">Result of the Service Execution</param>
        /// <param name="error">Error Message to be passed to client side</param>
        /// <param name="code">Error code to indicate the error</param>
        public DTO(object result, String errorMessage, ErrorCode error)
        {
            _error = error;
            _result = result;
            _errorMessage = errorMessage;
        }
        #endregion

        #region Properties

        /// <summary>
        /// Description of Error
        /// </summary>
        [DataMember]
        public String ErrorMessage
        {
            get
            {
                return _errorMessage;
            }
            set
            {
                _errorMessage = value;
            }
        }

        /// <summary>
        /// Result of Service Execution
        /// </summary>
        [DataMember]
        public object Result
        {
            get
            {
                return _result;
            }
            set
            {
                _result = value;
            }
        }

        /// <summary>
        /// Error code to determine the error
        /// </summary>
        [DataMember]
        public int Error
        {
            get
            {
                return (int)_error;
            }
            set
            {
                _error = (ErrorCode)Enum.Parse(typeof(ErrorCode), _error.ToString());
            }
        }
        #endregion
    }
}